<template>
  <view style="display: flex;flex-direction: column;height: 100vh;">
   <view class="header">
     <view class="back" @click="back()">
       <uni-icons type="left" size="20" color="#fff"></uni-icons>
     </view>
     <text>任务详情</text>
   </view>

    <view class="taskInfo">
      <view class="image">
        <image src="/static/taskImg.jpg" mode=""></image>
      </view>
      <view class="mainTaskDetail">
          <view class="textDetail">
            <view class="taskTitle">
              <view class="image">
                <image src="/static/task-logo.png"></image>
              </view>
              <text>{{item.mainTaskVO.mainTaskName}}</text>
            </view>
            <view class="taskDescribe">
              {{item.mainTaskVO.description}}
            </view>
            <view class="taskFooter">
              <view class="taskIntegral">
                积分：{{item.mainTaskVO.integral}}
              </view>
              <view class="taskComplete">
                已完成：{{item.mainTaskVO.mainCount}}
              </view>
            </view>
            <view class="main-status ok" v-if="item.mainTaskVO.completed === '已完成'">
              {{item.mainTaskVO.completed}}
            </view>
          </view>
      </view>
    </view>

    <view class="branchTask" v-if='item.mainTaskVO.completed == "已完成" '>
      <view class="branchTitle">
        支线任务
      </view>
      <view class="branchContainer" scroll-y="true">
        <block v-for="(item2,index) in item.branchTasksList" :key="index">
          <view class="scroll-item" @click="goBranchTask(item2.branchId)">
            <view class="task-Info">
              <view class="task-title">
                <view class="image">
                  <image src="/static/task-logo.png"></image>
                </view>
                <text>{{item2.branchTaskName}}</text>
              </view>
              <view class="task-integral">
                积分：{{item2.integral}}
              </view>
              <view class="completeCount">
                已完成 :{{item2.branchCount}}
              </view>
            </view>
            <view class="task-status ok" v-if="item2.completed == '已完成'">
              {{item2.completed}}
            </view>
          </view>
        </block>
      </view>
    </view>
   <view class="footer" v-else>
      <view class="btn-box">
        <view class="btn" @click="clockOn()">
          打卡
        </view>
      </view>
    </view>

  </view>
</template>

<script>
  import {
    mapState
  } from 'vuex'
  export default {
    data() {
      return {
        wh: 0,
        taskId: 0,
        item: {},
      };
    },
    onLoad(options) {
      const sysInfo = uni.getSystemInfoSync()
      this.wh = sysInfo.windowHeight
      this.taskId = options.taskId
      this.getTaskInfo()
    },
    onShow() {
      this.getNextStatus()
    },
    methods: {
      back() {
        uni.navigateBack()
      },
      async getTaskInfo() {
        let that = this
        const obj = {
          studentId: that.userInfo.studentId,
          mainTaskId: that.taskId
        }
        const data = await uni.$http.post('/users/tasks/maintask/detail', obj)
        console.log(data.data.data);
        this.item = data.data.data
      },
      async getNextStatus() {
        const res = await uni.$http.post(
          `/users/tasks/check/status/${this.taskId}?studentId=${this.userInfo.studentId}`)
      },
      goBranchTask(id) {
        uni.navigateTo({
          url: `/subpkg/branchTask/branchTask?taskId=${this.taskId}&branchId=${id}`
        })
      },
      clockOn() {
        if (this.item.mainTaskVO.completed == '已完成') return uni.$showMsg('您已经完成了该任务')
        const type = 1
        if (this.item.mainTaskVO.punchType === '定位打卡') {
          uni.navigateTo({
            url: `/subpkg/mapClock/mapClock?taskId=${this.taskId}&type=${type}`
          })
        } else if (this.item.mainTaskVO.punchType === '视频打卡') {
          uni.navigateTo({
            url: `/subpkg/videoClock/videoClock?taskId=${this.taskId}&type=${type}`
          })
        }
      }
    },
    computed: {
      ...mapState('my_user', ['userInfo'])
    }
  }
</script>

<style lang="scss">
  .header {
    position: relative;
    width: 100%;
    height: 140rpx;
    text-align: center;
    font-size: 36rpx;
    font-weight: 700;
    line-height: 170rpx;
    background-color:#b6edaa ;
    color: #fff;
    
    .back{
      position: absolute;
      top: 4rpx;
      left: 23rpx;
      height: 50rpx;
    }
  }
  
  .taskInfo {
    width: 100%;

    .image {
      width: 100%;
      height: 350rpx;

      image {
        width: 100%;
        height: 100%;
      }
    }

    .mainTaskDetail {
      height: 300rpx;
      background-color: #fff;
      
      .textDetail {
        position: relative;
        display: flex;
        flex-direction: column;
        margin-top: 20rpx;
        padding: 0 20rpx;
        padding-bottom: 10rpx;
        background-color: #fff;
      
        .taskTitle {
          display: flex;
          align-items: center;
          height: 80rpx;
          font-size: 36rpx;
          line-height: 80rpx;
          color: #333;
      
          .image {
            width: 40rpx;
            height: 40rpx;
      
            image {
              display: block;
              width: 100%;
              height: 100%;
            }
          }
      
          text {
            margin-left: 20rpx;
          }
        }
      
        .taskDescribe {
          padding: 10rpx 0;
          font-size: 32rpx;
          color: #555;
        }
      
        .taskFooter {
          display: flex;
          justify-content: space-between;
          margin-top: 10rpx;
          padding: 10rpx 0;
          color: #666;
      
          .taskIntegral {
            font-size: 30rpx;
            color: #046404;
          }
      
          .taskComplete {
            
            color: #888;
          }
        }
      
        .main-status {
          position: absolute;
          top: 30rpx;
          right: 30rpx;
          margin-bottom: 100rpx;
          padding: 6rpx 12rpx;
          color: #fff;
          font-size: 30rpx;
        }
      }
    }

  }

  .branchTask {
    display: flex;
    flex-direction: column;
    margin-top: 20rpx;
    flex: 1;
    
    .branchTitle {
      position: relative;
      width: 100%;
      height: 80rpx;
      padding: 0 60rpx;
      line-height: 80rpx;
      background-color: #fff;
      font-size: 30rpx;
    
      &::before {
        content: ' ';
        display: block;
        width: 5px;
        height: 20px;
        background-color: #b6eaae;
        position: absolute;
        left: 20rpx;
        top: 50%;
        transform: translateY(-50%);
      }
    }

    .branchContainer {
      flex: 1;
      padding-bottom: 20rpx;
      background-color: #fff;

      .scroll-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 94%;
        height: 200rpx;
        margin: 20rpx auto;
        padding: 20rpx 30rpx;
        background-color: #fff;
        box-shadow: 0 0 20rpx #ccc;
        box-sizing: border-box;

        .task-Info {
          display: flex;
          flex-direction: column;
          justify-content: space-between;
          width: 470rpx;
          height: 100%;

          .task-title {
            display: flex;
            align-items: center;
            height: 40rpx;
            margin-top: 10rpx;
            font-size: 34rpx;

            .image {
              width: 40rpx;
              height: 40rpx;

              image {
                width: 100%;
                height: 100%;
              }
            }

            text {
              margin-left: 20rpx;
            }
          }

          .task-integral {
            font-size: 30rpx;
            color: #777;
          }

          .completeCount {
            font-size: 30rpx;
            color: #777;
          }
        }

        .task-status {
          margin-bottom: 100rpx;
          padding: 6rpx 12rpx;
          color: #fff;
          font-size: 26rpx;
        }
      }

      .task-bottom {
        padding-top: 20rpx;
        padding-bottom: 150rpx;
        border-top: 1rpx solid #eee;
        color: #888;
        font-size: 36rpx;
        text-align: center;
      }
    }
  }

  .ok {
    background-color: #b6edaa;
  }

  .ing {
    background-color: orange;
  }

  .footer {
    position: relative;
     width: 90%;
     height: 780rpx;
     margin: 0 auto;
     margin-top: 50rpx;
     background-color: #fff;
     
    .btn-box {
      position: absolute;
      top: 220rpx;
      left: 180rpx;
      width: 310rpx;
      height: 310rpx;
      border: 8rpx solid #c4eebe;
      border-radius: 50%;

      .btn {
        width: 280rpx;
        height: 280rpx;
        margin: 15rpx auto;
        border-radius: 50%;
        background-color: #b6edaa;
        text-align: center;
        line-height: 280rpx;
        font-size: 50rpx;
        color: #fff;
      }
    }
  }
</style>